package com.jjyu.service.impl;

import com.jjyu.entity.FavoriteRestaurant;
import com.jjyu.dao.FavoriteRestaurantMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FavoriteRestaurantService {

    @Autowired
    private FavoriteRestaurantMapper favoriteRestaurantMapper;

    public void addFavorite(FavoriteRestaurant favoriteRestaurant) {
        // 检查收藏是否已存在
        if (favoriteRestaurantMapper.findByUserIdAndRestaurantId(favoriteRestaurant.getUserId(), favoriteRestaurant.getRestaurantId()) == null) {
            favoriteRestaurantMapper.insert(favoriteRestaurant);
        }
    }

    public void removeFavorite(Integer id) {
        favoriteRestaurantMapper.deleteById(id);
    }

    public List<FavoriteRestaurant> getFavoritesByUserId(Integer userId) {
        return favoriteRestaurantMapper.findByUserId(userId);
    }
}
